package com.xdf.ecommerce.utils;

import com.xdf.ecommerce.constant.AuthorityConstant;
import com.xdf.ecommerce.constant.CommonConstant;
import sun.misc.BASE64Decoder;

import java.io.IOException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

/**
 * @author chanchaw
 * @create 2025-10-16 7:49
 */
public class RSAUtils {
    public static PrivateKey getPrivateKey(String privateKeyStr) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        PKCS8EncodedKeySpec pkcs8 = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(privateKeyStr));
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePrivate(pkcs8);
    }
}
